package com.dhcc.bpm.common.config;


import com.dhcc.bpm.common.interceptor.SsoInterceptor;
import com.dhcc.bpm.common.interceptor.TokenInterceptor;
import org.springblade.core.secure.registry.SecureRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName BladeConfiguration
 * @Description 配置类
 * @Author xiafayu
 * @Date 2020/2/21 0021 15:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 **/
@Configuration
public class BladeConfiguration implements WebMvcConfigurer {

	@Autowired
    TokenInterceptor tokenInterceptor;

	@Autowired
    SsoInterceptor ssoInterceptor;
//	exclude排除
	@Override
	public void addInterceptors(InterceptorRegistry registry) {

		registry.addInterceptor(ssoInterceptor)
				.addPathPatterns("/**")
				.excludePathPatterns("/blade-flow/process/resource-view")
				.excludePathPatterns("/blade-flow/process/diagram-view")
				.excludePathPatterns("/blade-flow/manager/check-upload")
				.excludePathPatterns("/bpm-system/appapi/getApiListByProductId")
				.excludePathPatterns("/bpm-workflow/approve/commitTask")
				.excludePathPatterns("/bpm-workflow/approve/refreshData")
                .excludePathPatterns("/bpm-common/plupload/openApi/**")
                .excludePathPatterns("/**");

		registry.addInterceptor(tokenInterceptor)
				.addPathPatterns("/**")
				.excludePathPatterns("/blade-auth/**")
//				.excludePathPatterns("/bpm-system/gatewaylogday/**")
//				.excludePathPatterns("/bpm-log/*")
				.excludePathPatterns("/blade-system/**")
				.excludePathPatterns("/bpm-gateway/gatewaylog/gatewayLoglist")
				.excludePathPatterns("/blade-system/menu/routes")
				.excludePathPatterns("/bpm-common/plupload/openApi/**")
				.excludePathPatterns("/blade-system/role/grant")
				.excludePathPatterns("/blade-system/menu/auth-routes")
				.excludePathPatterns("/blade-system/menu/top-menu")
				.excludePathPatterns("/blade-flow/process/resource-view")
				.excludePathPatterns("/blade-flow/process/diagram-view")
				.excludePathPatterns("/blade-flow/manager/check-upload")
				.excludePathPatterns("bpm-common/plupload/openApi/")
				.excludePathPatterns("/bpm-system/appapi/getApiListByProductId")
				.excludePathPatterns("/bpm-workflow/approve/commitTask")
				.excludePathPatterns("/bpm-workflow/approve/refreshData")
				.excludePathPatterns("/doc.html")
				.excludePathPatterns("/js/**")
				.excludePathPatterns("/webjars/**")
				.excludePathPatterns("/swagger-resources/**")
				.excludePathPatterns("/blade-system/dict/getDict")
                .excludePathPatterns("/druid/**")
                .excludePathPatterns("/**");
	}

	@Bean
	public SecureRegistry secureRegistry() {
		SecureRegistry secureRegistry = new SecureRegistry();
		secureRegistry.setEnabled(true);
		secureRegistry.excludePathPatterns("/blade-auth/**");
//		secureRegistry.excludePathPatterns("/bpm-system/gatewaylogday/**");
//		secureRegistry.excludePathPatterns("/blade-log/**");
		secureRegistry.excludePathPatterns("/blade-system/**");
		secureRegistry.excludePathPatterns("/bpm-gateway/gatewaylog/gatewayLoglist");
		secureRegistry.excludePathPatterns("/blade-system/menu/routes");
		secureRegistry.excludePathPatterns("/blade-system/menu/auth-routes");
		secureRegistry.excludePathPatterns("/blade-system/menu/top-menu");
		secureRegistry.excludePathPatterns("/blade-flow/process/resource-view");
		secureRegistry.excludePathPatterns("/blade-flow/process/diagram-view");
		secureRegistry.excludePathPatterns("/bpm-common/plupload/openApi/**");
		secureRegistry.excludePathPatterns("/blade-flow/manager/check-upload");
		secureRegistry.excludePathPatterns("/bpm-system/appapi/getApiListByProductId");
		secureRegistry.excludePathPatterns("/bpm-workflow/approve/commitTask");
		secureRegistry.excludePathPatterns("/bpm-workflow/approve/refreshData");
		secureRegistry.excludePathPatterns("/doc.html");
		secureRegistry.excludePathPatterns("/js/**");
		secureRegistry.excludePathPatterns("/webjars/**");
		secureRegistry.excludePathPatterns("/swagger-resources/**");
		secureRegistry.excludePathPatterns("/druid/**");
        secureRegistry.excludePathPatterns("/**");
		secureRegistry.excludePathPatterns("/bpm-papc/batchrecord/getZJYWBatchRecord");
		return secureRegistry;
	}

	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/cors/**")
			.allowedOrigins("*")
			.allowedHeaders("*")
			.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
			.maxAge(3600)
			.allowCredentials(true);
	}

}
